SRC           = kernel.c led.c serialdriver.c
OBJ           = kernel.o led.o serialdriver.o
CC            = arm-elf-gcc
CFLAGS        = -Wall
LD            = arm-elf-ld
LSCRIPT       = link_sdram.ld
OBJCOPY       = arm-elf-objcopy
MKIMAGE       = mkimage
MKIMAGE_FLAGS = -A arm -O linux -T kernel -C none -a 0x22000000 -e 0x22000000
IMAGE         = kernel
BOOTIMAGE     = system.img
DEPENDFILE    = depend

all:	$(BOOTIMAGE)

.PHONY: clean dep

clean:
	rm -f *.o *~
	rm -f $(IMAGE) $(IMAGE).bin $(BOOTIMAGE)

%.o: %.c
	$(CC) $(CFLAGS) -c $<

%.o: %.S 
	$(CC) $(CFLAGS) -c -x assembler $<

dep: $(SRC)
	$(CC) -MM $(SRC) > $(DEPENDFILE)

-include $(DEPENDFILE)

$(IMAGE): $(OBJ)
	$(LD) $(LDFLAGS) -T$(LSCRIPT) -o $@ $^
	$(OBJCOPY) $@ -Obinary $@.bin

$(BOOTIMAGE): $(IMAGE)
	$(MKIMAGE) $(MKIMAGE_FLAGS) -d $(IMAGE).bin $@

install: $(BOOTIMAGE)
	arm-install-image $(BOOTIMAGE)

handin:
	@handin

